package com.sinba.common.news.action;

import com.opensymphony.xwork2.ActionSupport;

import com.sinba.common.dto.PageDTO;
import com.sinba.common.news.dto.CategoryDTO;
import com.sinba.common.news.dto.IndexMenuDTO;
import com.sinba.common.news.service.ICategoryService;

import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings( "serial" )
public class CategoryAction
    extends ActionSupport
{
    @Autowired
    private ICategoryService categoryService;
    private PageDTO pageDTO;
    private CategoryDTO categoryDTO = new CategoryDTO(  );
    private Long[] ids;
    private String sord;
    private String sidx;
    private int page = 1;
    private int rows = 10;
    private List<IndexMenuDTO> indexMenu = new ArrayList<IndexMenuDTO>(  );

    public PageDTO getPageDTO(  )
    {
        return pageDTO;
    }

    public void setPageDTO( PageDTO pageDTO )
    {
        this.pageDTO = pageDTO;
    }

    public CategoryDTO getCategoryDTO(  )
    {
        return categoryDTO;
    }

    public void setCategoryDTO( CategoryDTO categoryDTO )
    {
        this.categoryDTO = categoryDTO;
    }

    public Long[] getIds(  )
    {
        return ids;
    }

    public void setIds( Long[] ids )
    {
        this.ids = ids;
    }

    public String getSord(  )
    {
        return sord;
    }

    public void setSord( String sord )
    {
        this.sord = sord;
    }

    public String getSidx(  )
    {
        return sidx;
    }

    public void setSidx( String sidx )
    {
        this.sidx = sidx;
    }

    public int getPage(  )
    {
        return page;
    }

    public void setPage( int page )
    {
        this.page = page;
    }

    public int getRows(  )
    {
        return rows;
    }

    public void setRows( int rows )
    {
        this.rows = rows;
    }

    public List<IndexMenuDTO> getIndexMenu(  )
    {
        return indexMenu;
    }

    public void setIndexMenu( List<IndexMenuDTO> indexMenu )
    {
        this.indexMenu = indexMenu;
    }

    public String findCategoryPager(  )
    {
        int start = ( page - 1 ) * rows;
        categoryDTO.setStart( start );
        categoryDTO.setLimit( rows );
        pageDTO = categoryService.findCategoryPager( categoryDTO, sord, sidx );

        if ( pageDTO != null )
        {
            pageDTO.setPage( page );
            pageDTO.setRows( rows );
        }

        return SUCCESS;
    }

    public String saveCategory(  )
    {
        categoryService.saveCategory( categoryDTO );

        return SUCCESS;
    }

    public String editCategory(  )
    {
        categoryService.editCategory( categoryDTO );

        return SUCCESS;
    }

    public String deleteCategory(  )
    {
        categoryService.deleteCategory( ids );

        return SUCCESS;
    }

    public String findCategoryInfo(  )
    {
        categoryDTO = categoryService.findCategoryInfo( categoryDTO.getCategoryId(  ) );

        return "categoryDTO";
    }

    public String findIndexMenu(  )
    {
        indexMenu = categoryService.findIndexMenu( null, categoryDTO );

        return "indexMenu";
    }
}
